package controller;

import java.awt.GridBagLayout;
import java.awt.event.*;
import javax.swing.*;

import model.Simulator;
import model.Sound;
import controller.JTextFieldNumbersOnly;

/**
 * The class StepsController extends AbstractController
 * @author Arjan Frans, Alwin Rombout, Jelte Verbree, Brendan Kanters
 * @version 1.0
 */
public class StepsController extends AbstractController implements ActionListener {
	private static final long serialVersionUID = -3762097023651830639L;
	private JButton startButton;
	private JButton stopButton;
    private JTextField stepsTextField;
    private JButton atomicDisaster;
    private Icon ButtonIcon;
    
    /**
     * Create a new StepsController using the simulator
     * @param simulator
     */
    public StepsController(Simulator simulator)
    {
        super(simulator);
        
        stepsTextField = new JTextFieldNumbersOnly("100");
        this.add(stepsTextField);      
        
        startButton = new JButton("Start");
        this.add(startButton);
        startButton.addActionListener(this);
        
        stopButton = new JButton("Stop");
        this.add(stopButton);
        stopButton.addActionListener(this);
        
        ButtonIcon = new ImageIcon("Images/AtomicIcon.png");
        
        atomicDisaster = new JButton();
        atomicDisaster.setIcon(ButtonIcon);
        atomicDisaster.addActionListener(this);
        this.add(atomicDisaster);
        
    }

    @Override
    /**
     * Overrides the actionPerformed method
     */
    public void actionPerformed(ActionEvent e) {
            if(simulator.isReady()) {
	            if (e.getSource()==startButton) 
	            {   
	            	int steps = Integer.parseInt(stepsTextField.getText());
	        		simulator.runSimulation(steps);
	            }
	            else if (e.getSource()==stopButton) 
	            {
	                simulator.stopSimulation();
	            }
	            else if(e.getSource()==atomicDisaster)
	            {
	            	simulator.nuke(true); 
	            }
            }
            else {
            	JOptionPane.showMessageDialog(this,
            		    "Sla de settings eerst op!",
            		    "Save settings warning",
            		    JOptionPane.WARNING_MESSAGE);
            }
    }
}
